/*
TO RUN THESE DOS, YOU NEED THE FOLLOWING DATA FILES: MANY OF THE POSTED FILES ARE PSEUDO DATA FILES MIMICKING THE STUCTURE OF THE UNDERLYING DATA. THESE FILES ARE NOT INCLUDED DUE TO LICENSE REQUIREMENTS AND ARE MARKED WITH ***, available through WRDS with license

	* 00_dd_annual, ***PSEUDO FILE. derived distance-to-default &probability of default, shared by Janet Gao
	* 00_leadshares, ***PSEUDO FILE. available by dealscan download of lead lender shares from WRDS 
	* 00_rawTCdata, the manually collected trade credit dataset
	* 01_comp_basic_raw_vars,  ***PSEUDO FILE. available from compustat NA annual file from WRDS 
	* 02_supply_chain_links, customer-supplier panel, combined data from Ted Fee, Janet Gao, Yixin Liu, supplemented with WRDS' customer gvkey links
	* 03_ratings, ***PSEUDO FILE. available from WRDS s&p ratings from WRDS ***
	* 05_differentiation_data, from Giannetti, Burkart, and Ellingsen (2011), sourced from the paper appendix
	* 07_Kdata, the hand-collected loan contract data
	* 13_Auds, ***PSEUDO FILE. auditors data available from compustat via WRDS 
	* 15_Kdata_Cust, the hand-collected loan contract data with customer-specific details
	* DS_Links2018, an excel file from Michael Roberts website
	* 00_facility, ***PSEUDO FILE. a dealscan loan facilities, available through WRDS 
	* 00_package,  ***PSEUDO FILE. dealscan loan packages, available through WRDS 
	* 15_Kdata_Cust, the hand-collected loan contract data with customer-level details
	
RUNNING THESE DOS WILL PRODUCE MULTIPLE INTERMEDIATE DATASETS:
	* 04_prepped_data
	* 06_everDS
	* 07b_kdata_pkg
	* 08_commons
	* 08_supplierDS
	* 09_cloan
	* 10_leads
	* 11_portdefaults
	* 11b_portdefaults_pkgdate
	* 12_PreKData
	* 14_prematch*/
	
	
cd "~\JFQA_LsL_SharablePseudo"/*set local directory*/

/*
A. PREP THE TC DATA FOR ANALYSIS
*/

do Do1_PrepSample /*combines tc data, supply chain data, compustat controls into a sample, pre-restricting to pairs with available tc data*/

/*
B. PREPARE DEALSCAN FILES 
*/
do Do2_SupplierDealscan /*prepares a running panel of years supplier has outstanding loan*/
do Do2b_CustomerDealscan /*prepares a running panel of years customer has outstanding loan, synced to supplier fiscal year*/
do Do3_MoreDealscanData /*preps file of leads and common lender indicator, in running cust-supp panel*/
do Do4_Defaults /*preps 2 files with lender portfolio default; both are running panels, but first updates to reflect lender defaults over the last two years; second is defaults at the time of package*/
/*
C. ANALYSIS NOT USING CONTRACT DATA
*/
do Do5_PreKAnalysis /*uses data restricted to available tc data, with the following tables/figures from the paper:
	* TABLE 1: SUMMARY STATS
	* TABLE 2: BASELINE
	* TABLE 3: TC ACROSS SUPPLIER PORTFOLIO
	* TABLE IA-2: ROBUSTNESS CHECKS, ALT DEPENDENCE AND TC CONSTRUCTION, INCLU SALES GR CONTROL
	* TABLE IA-5: ROBUSTNESS CHECK, LIMIT TO SUPP-YEARS WITH ALL CUSTS' TC REPORTED
	* TABLE IA-6: PRICING TESTS, GROSS MARGIN AS DEP VAR AND SUBSAMPLING
	* TABLE IA-7: ROBUSTNESS, LT RELATIONSHIPS
	* TABLE IA-8: MONITORING AND PORTFOLIO DEFAULT VARIATION
	* TABLE IA-9: CUSTOMER DEFAULT AND PAYABLE DAYS VARIATION
	* FIGURE 1: UNIVARIATE PATTERNS
	* FIGURE 2: MONOTONICITY AND CONSISTENCY OVER TIME OF BASELINE RESULT
*/
/*
D. ANALYSIS USING BROADER SAMPLE INCLUDING TC UNAVAILABLE
*/
do Do6_SelectionWork /*addresses selection concerns; note this file takes some time, due to preparation of the auditor instrument. it also hits some errors in the matched sample construction due to no close matches for some observations, so the file isn't set up to run in its entirety without interacting with it. produces the following tables:*/
	* TABLE IA-1: COMPARISON OF REPORTED/NON-REPORTED
	* TABLE IA-3: HECKMAN SELECTION TEST, MATCHED SAMPLE +ENTROPY-BALANCED HI/LOW AUDITOR TESTS
	* TABLE IA-4: COMPARISONS OF HI/LOW AUDITOR SAMPLES AFTER MATCHING OR EBALANCING
*/

/*
E. ANALYSIS USING CONTRACT DATA
*/
do Do7_KAnalysis /*uses data with available loan contract characteristics. produces the following tables/figures:
	* TABLE 4: SUM STATS OF CONTRACT CHARACTERISTICS
	* TABLE 5: VARIATION ALONG CONTRACT STRICTNESS
	* TABLE 6: FACTORS OF CONTRACT STRICTNESS
	* TABLE 7: EFFECTS OF REC AUSTERITY ON CUST RELATIONSHIPS
	* TABLE 9: FIRM OUTCOMES, USING HIDEF AS AN INSTRUMENT
	* TABLE IA-10: PROPENSITY TO BREAK CONCENTRATION LIMITS
	* FIGURE 3: DISTRIBUTION OF GENERIC AND CUST-SPECIFIC LIMITS
	* FIGURE 4: RECEIVABLE LIMITS AND REALIZED OUTCOMES
	* FIGURE 5: CUSTOMER SALES GROWTH AND CONTRACT STRICTNESS
	*/